package com.gonsin.gview.model.table;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.gonsin.gview.model.GBoardModel;
import com.gonsin.gview.model.data.GTableDataModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel("列表的board")
public class GTableBoardModel extends GBoardModel {
    @ApiModelProperty("页面类型")
    private String boardType = "table";

//    {
//        setBoardType("table");
//    }

    @ApiModelProperty("列表标题的描述")
    private GHeaderModel header;

    @ApiModelProperty("列表行个数")
    private int count = 10;

    @Deprecated
    @ApiModelProperty("for循环的时候，每一行的对象的名字")
    private String itemName;

    @ApiModelProperty("每行的描述")
    private List<GColumnModel> columns;

    @ApiModelProperty("页面数据")
    private GTableDataModel tableData;


    @Override
    public GBoardModel tClone() {
        GTableBoardModel model = new GTableBoardModel();
        BeanUtil.copyProperties(this, model, CopyOptions.create().setIgnoreNullValue(true));
        if(header != null){
            model.header = header.tClone();
        }
        if(columns != null){
            model.columns = new ArrayList<>();
            for(GColumnModel t : columns){
                model.columns.add(t.tClone());
            }
        }
        return model;
    }

}
